package com.zj.dataSource;

import javax.sql.DataSource;
import java.lang.reflect.Field;
import java.util.Properties;

public class UnpooledDataSourceFactory implements DataSourceFactory {
    protected DataSource dataSource = (DataSource) new UnpooledDataSource();


    public UnpooledDataSourceFactory() {
    }




    @Override
    public DataSource getDataSource() {
        return dataSource;
    }

    @Override
    public void setProperties(Properties properties) {
        //mybatis用这种方式将属性设置到DataSource的原因？
//        MetaObject metaDataSource = SystemMetaObject.forObject(this.dataSource);
        try{

        Field[] declaredFields = dataSource.getClass().getDeclaredFields();
        for(Field fe:declaredFields){
            fe.setAccessible(true);
            fe.set(dataSource,properties.getProperty(fe.getName()));
            System.out.println(fe.getName());
        }
        }catch (Exception e){
            e.printStackTrace();
        }

    }


}
